﻿using System;
using System.ComponentModel;
using System.Drawing;

namespace ExFlash.Records
{
    [TypeConverter(typeof(RectangleRecordConverter))]
    public class RectangleRecord : ISwfSerializable, ICloneable
    {
        [Browsable(false)]
        public Byte Nbits
        {
            get;
            private set;
        }

        public int Xmin
        {
            get;
            private set;
        }
        
        public int Xmax
        {
            get;
            private set;
        }

        public int Ymin
        {
            get;
            private set;
        }

        public int Ymax
        {
            get;
            private set;
        }

        public Point GetCenter()
        {
            return new Point((Xmin + Xmax) / 2, (Ymin + Ymax) / 2);
        }

        #region ISwfSerializable Members

        public void SwfDeserialize(BinaryBitReader reader)
        {
            Nbits = (Byte)reader.ReadUInt32(5);
            Xmin = reader.ReadInt32(Nbits);
            Xmax = reader.ReadInt32(Nbits);
            Ymin = reader.ReadInt32(Nbits);
            Ymax = reader.ReadInt32(Nbits);
            reader.AlignBits();
        }

        public void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            return this.MemberwiseClone();
        }

        #endregion
    }

    public class RectangleRecordConverter : ExpandableObjectConverter
    {

    }
}
